package rdd.operate;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import scala.Tuple2;

import java.util.Arrays;
import java.util.List;

public class Spark67_Operate_Save {
    public static void main(String[] args) {
        final SparkConf conf = new SparkConf();
        conf.setMaster("local");
        conf.setAppName("spark");
        final JavaSparkContext jsc = new JavaSparkContext(conf);

        final List<Integer> nums = Arrays.asList(4,3,2,1);
        final JavaRDD<Integer> rdd = jsc.parallelize(nums,2);

        JavaPairRDD<String, Integer> pairRDD = rdd.mapToPair(
                num -> new Tuple2<>("a", num)
        );

        //文件不能存在
        pairRDD.saveAsTextFile("output1");
        pairRDD.saveAsObjectFile("output2");
        jsc.close();
    }
}
